package com.zhumr.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhumr.model.CrewInfo;
import com.zhumr.service.ICrewInfoService;

/**
 * 剧组
 * 
 * @author HP
 *
 */
@Controller
@RequestMapping("/webCrew")
public class CrewInfoController {
	@Autowired
	private ICrewInfoService crewService;

	/**
	 * 所有的剧组
	 * 
	 * @param request
	 * @param Area
	 *            拍摄地址
	 * @param TypeN
	 *            类型
	 * @param likeString
	 *            模糊字段
	 * @return
	 */
	@RequestMapping("/getAllCrew")
	@ResponseBody
	public Map<String, Object> getAllCrew(HttpServletRequest request, String Area, String TypeN, String likeString) {

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("Area", Area);
		paramMap.put("TypeN", TypeN);
		paramMap.put("likeString", likeString);

		List<CrewInfo> crewList = crewService.getAllCrew(paramMap);

		Map<String, Object> result = new HashMap<String, Object>();
		if (crewList != null) {
			result.put("code", "0");
			result.put("crew", crewList);
		} else {
			result.put("code", "1");
			result.put("crew", null);
		}
		return result;
	}

	/**
	 * 剧组详情
	 * 
	 * @param request
	 * @param id
	 * @return
	 */
	@RequestMapping("/getCrewById")
	@ResponseBody
	public Map<String, Object> getCrewByid(HttpServletRequest request, int id) {

		CrewInfo crew = crewService.getCrewById(id);
		Map<String, Object> result = new HashMap<String, Object>();
		if (crew != null) {
			result.put("code", "0");
			result.put("crew", crew);
		} else {
			result.put("code", "1");
			result.put("crew", null);
		}
		return result;
	}

	/**
	 * 我的通告
	 * 
	 * @param request
	 * @param ReleaseUserId
	 * @return
	 */
	@RequestMapping("/myCrewList")
	@ResponseBody
	public Map<String, Object> myCrewList(HttpServletRequest request, int ReleaseUserId) {

		List<CrewInfo> crewList = crewService.myCrewList(ReleaseUserId);

		Map<String, Object> resultMap = new HashMap<String, Object>();

		if (crewList != null) {
			resultMap.put("code", "0");
			resultMap.put("crewList", crewList);
		} else {
			resultMap.put("code", "1");
			resultMap.put("crewList", null);
		}

		return resultMap;
	}

	/**
	 * 我的通告
	 * 
	 * @param request
	 * @param ReleaseUserId
	 * @return
	 */
	@RequestMapping("/delectMyCrew")
	@ResponseBody
	public Map<String, Object> delectMyCrew(HttpServletRequest request, int id) {

		int i = crewService.delectMyCrew(id);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (i > 0) {
			resultMap.put("code", "0");
		} else {
			resultMap.put("code", "1");
		}
		return resultMap;
	}
}
